package cn.imvc.app.controllers.info;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.controllers.goods.GoodsControllerImpl;
import cn.imvc.app.entities.PushMessage;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.app.models.PushMessageModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class PushMessageControllerImpl implements PushMessageController{
	static Logger logger = Logger.getLogger(PushMessageControllerImpl.class);
	public Page<PushMessage> page;
	public ViewRequest viewRequest;
	private PushMessage pushMessage;
	private int id;
	
	@Autowired
	PushMessageModel pushMessageModel;
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		return null;
	}

	public String index() {
		if(viewRequest==null){
			viewRequest = new ViewRequest();
		}
		page = pushMessageModel.find(viewRequest);
		return "push-message/index";
	}

	public String show() {
		return null;
	}

	public String editNew() {
		return "push-message/edit";
	}

	public String create() {
		pushMessageModel.save(pushMessage);
		loggingModel.info(logger,"添加推送消息："+pushMessage.getTitle());
		return Render.json(new DialogBean("200","添加成功","","closeCurrent"));
	}

	public String edit() {
		pushMessage = pushMessageModel.get(id);
		return "push-message/edit";
	}

	public String update() {
		pushMessageModel.update(id,pushMessage);
		loggingModel.info(logger,"修改推送消息："+pushMessage.getTitle());
		return Render.json(new DialogBean("200","修改成功","","closeCurrent"));
	}

	public String destroy() {
		pushMessageModel.delete(id);
		loggingModel.info(logger,"删除推送消息："+id);
		return Render.json(new DialogBean("200","删除成功","closeCurrent"));
	}

	public String destroyBatch() {
		return null;
	}

	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public PushMessage getPushMessage() {
		return pushMessage;
	}

	public void setPushMessage(PushMessage pushMessage) {
		this.pushMessage = pushMessage;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

}
